#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
    bool canJump(vector<int>& nums) {
        int l = 0, r = 0;
        while(r < nums.size() - 1)
        {
            int next_l = r + 1, next_r = 0;
            for(int i = l; i <= r; ++i)
                next_r = max(next_r, i + nums[i]);
            if(next_r < next_l) return false;
            l = next_l, r = next_r;
        }
        return true;
    }
};